#ifndef _HESAI_DATA_TYPE_H_
#define _HESAI_DATA_TYPE_H_
#include "cyber/cyber.h"
namespace apollo {
namespace drivers {
namespace lidar_hesai {
const int UDP_DATA_SIZE = 1076;
const int UDP_DATA_SIZE_WITH_SEQUENCE = 1080;

typedef uint8_t HesaiLidarPacketData[UDP_DATA_SIZE_WITH_SEQUENCE];

const int PACKET_PER_FRAME = 250;
const int AZIMUTH_PER_PACKET = 36000 / PACKET_PER_FRAME;
const int AZIMUTH_PER_BLOCK = AZIMUTH_PER_PACKET / 8;
const int POINT_PER_PACKET = 8 * 32;
const int POINT_PER_FRAME = POINT_PER_PACKET * PACKET_PER_FRAME;

const int MAIN_DATA_IDX = 12;
const int BLOCK_NUM = 8; 
const int UNIT_PER_BLOCK = 32;

const int TAIL_IDX = 1052;

const int TIME_IDX = 1065;

const int SEQ_IDX = 1076;

static const double elevAngleMap[] = {15.0,  14.0,  13.0,  12.0,  11.0,  10.0,
                                      9.0,   8.0,   7.0,   6.0,   5.0,   4.0,
                                      3.0,   2.0,   1.0,   0.0,   -1.0,  -2.0,
                                      -3.0,  -4.0,  -5.0,  -6.0,  -7.0,  -8.0,
                                      -9.0,  -10.0, -11.0, -12.0, -13.0, -14.0,
                                      -15.0, -16.0};  // namespace hesai

/************Hesai_XT*******************************/
typedef struct HS_LIDAR_XT_Header {
  uint16_t sob;             // 0xFFEE 2bytes
  uint8_t chProtocolMajor;  // Protocol Version Major 1byte
  uint8_t chProtocolMinor;  // Protocol Version Minor 1byte
  uint8_t chLaserNumber;    // laser number 1byte
  uint8_t chBlockNumber;    // block number 1byte
  uint8_t chReturnType;  // return mode 1 byte  when dual return 0-Single Return
  uint8_t chDisUnit;     // Distance unit, 4mm
 public:
  HS_LIDAR_XT_Header() {
    sob = 0;
    chProtocolMajor = 0;
    chProtocolMinor = 0;
    chLaserNumber = 0;
    chBlockNumber = 0;
    chReturnType = 0;
    chDisUnit = 0;
  }
} HS_LIDAR_XT_Header;

typedef struct HS_LIDAR_XT_Unit {
  double distance;
  uint8_t intensity;
  uint8_t confidence;
} HS_LIDAR_XT_Unit;

typedef struct HS_LIDAR_XT_Block {
  uint16_t azimuth;  // packet angle  ,Azimuth = RealAzimuth * 100
  HS_LIDAR_XT_Unit units[UNIT_PER_BLOCK];
} HS_LIDAR_XT_Block;

typedef struct HS_LIDAR_XT_Packet {
  HS_LIDAR_XT_Header header;
  HS_LIDAR_XT_Block blocks[BLOCK_NUM];
  unsigned int timestamp;  // us
  uint8_t echo;
  unsigned char utc_time[6];
} HS_LIDAR_XT_Packet;

}  // namespace lidar_hesai
}  // namespace drivers
}  // namespace apollo

#endif